package com.dragons.dragonsvf.utils.secret;
import java.io.UnsupportedEncodingException;

import org.springframework.util.Base64Utils;
public class Base64Util {
    /**
     * 解码base64编码的字符串
     *
     * @param source
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String decodeFromString(String source) {
        String str = "";
        try {
            byte[] bt = Base64Utils.decodeFromString(source);
            str = new String(bt, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(); // To change body of catch statement use File |
            // Settings | File Templates.
        }
        return str;
    }

    /**
     * 对字符串进行base64编码
     *
     * @param source
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String encodeToString(String source) {
        byte[] bt = new byte[0];
        try {
            bt = source.getBytes("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace(); // To change body of catch statement use File |
            // Settings | File Templates.
        }
        return Base64Utils.encodeToString(bt);
    }
}
